package org.zachary.agent.domain.aggregate_model.user;

import jakarta.persistence.Embeddable;
import lombok.Getter;

import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;

@Getter
@Embeddable
public class Address implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;


    private String province;
    private String city;
    private String county;
    private String township;

    public Address( String province, String city, String county, String township ) {
        if(province.isEmpty() || city.isEmpty() || county.isEmpty() || township.isEmpty()) {
            throw new IllegalArgumentException("地址参数缺失");
        }
        this.province = province;
        this.city = city;
        this.county = county;
        this.township = township;
    }

    protected Address() {}



    @Override
    public String toString() {
        return String.join(", ", township,province, city, county);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Address address = (Address) o;
        return Objects.equals(province, address.province) &&
                Objects.equals(city, address.city) &&
                Objects.equals(county, address.county)&&
                Objects.equals(township, address.township);
    }

    @Override
    public int hashCode() {
        return Objects.hash( province, city, county,township);
    }
}